import 'package:flutter/material.dart';

import '../constants.dart';
import '../tools/refresh_load_state.dart';

class ScrollScreen extends StatefulWidget {
  const ScrollScreen({Key? key}) : super(key: key);

  @override
  RefreshLoadState createState() => RefreshLoadState<ScrollScreen, int>(
      initData: List.generate(20, (index) => index + 1),
      getPage: (page, pageSize) async {
        if (page > 20) {
          return [];
        }
        return List.generate(
            pageSize, (index) => (page - 1) * pageSize + index + 1);
      },
      itemBuilder: (val) => Container(
            padding: EdgeInsets.all(kDefaultPadding),
            height: 100,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(10),
                bottomRight: Radius.circular(10),
              ),
            ),
            child: Text("第$val个记录"),
          ),
      noMore: () => Container(
            padding: EdgeInsets.all(kDefaultPadding),
            alignment: Alignment.center,
            constraints: BoxConstraints(
              minHeight: kDefaultPadding * 3,
            ),
            child: Text("没有更多的数据！"),
          ),
      gap:SizedBox(height:kDefaultPadding),
      wrapper: (w) => Scaffold(
            appBar: AppBar(title: Text("上拉刷新测试")),
            body: w,
          ));
}
